package cn.scw.project.facility.controller;

import cn.scw.common.constant.SysConsts;
import cn.scw.framework.aspectj.lang.annotation.Log;
import cn.scw.framework.aspectj.lang.enums.BusinessType;
import cn.scw.framework.web.controller.BaseController;
import cn.scw.framework.web.domain.AjaxResult;
import cn.scw.framework.web.page.TableDataInfo;
import cn.scw.project.facility.domain.FacFacilityRepairs;
import cn.scw.project.facility.domain.netework.bean.FacFacilityRepairsAddReq;
import cn.scw.project.facility.domain.netework.bean.FacFacilityRepairsListReq;
import cn.scw.project.facility.domain.netework.bean.FacFacilityRepairsUpdReq;
import cn.scw.project.facility.service.IFacFacilityRepairsService;
import cn.scw.project.system.domain.SysDictData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备报修Controller
 *
 * @author api
 * @date 2020-05-20
 */
@Api(tags = "设备报修")
@RestController
@RequestMapping(SysConsts.CONTEXT_PATH+"/facility/facilityRepairs")
public class FacFacilityRepairsController extends BaseController {
    @Autowired
    private IFacFacilityRepairsService facFacilityRepairsService;

    @ApiOperation("查询设备报修类型")
    @GetMapping("/type/list")
    public TableDataInfo typeList() {
        startPage();
        List<SysDictData> list = facFacilityRepairsService.selectFacFacilityRepairsTypeList();
        return getDataTable(list);
    }

    @ApiOperation("查询设备报修列表")
    //@PreAuthorize("@ss.hasPermi('facility:repairs:list')")
    @GetMapping("/list")
    public TableDataInfo list(FacFacilityRepairsListReq req) {
        startPage();
        List<FacFacilityRepairs> list = facFacilityRepairsService.selectFacFacilityRepairsList(req);
        return getDataTable(list);
    }

    @ApiOperation("查询我的报修列表")
    @GetMapping("/user/list")
    public TableDataInfo userList(@RequestParam(required = false)@ApiParam("状态（null值查全部）") Boolean isSolve) {
        startPage();
        List<FacFacilityRepairs> list = facFacilityRepairsService.selectFacFacilityRepairsListByUserId(isSolve);
        return getDataTable(list);
    }

    @ApiOperation("获取设备报修详细信息")
    //@PreAuthorize("@ss.hasPermi('facility:repairs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(facFacilityRepairsService.selectFacFacilityRepairsById(id));
    }

    @ApiOperation("新增设备报修")
    @Log(title = "设备报修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(FacFacilityRepairsAddReq req) {
        return toAjax(facFacilityRepairsService.insertFacFacilityRepairs(req));
    }

    @ApiOperation("新增设备报修")
    @Log(title = "设备报修", businessType = BusinessType.INSERT)
    @PostMapping("/login/add")
    public AjaxResult loginAdd(FacFacilityRepairsAddReq req) {
        return toAjax(facFacilityRepairsService.insertFacFacilityRepairs(req));
    }

    @ApiOperation("修改设备报修")
    //@PreAuthorize("@ss.hasPermi('facility:repairs:edit')")
    @Log(title = "设备报修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(FacFacilityRepairsUpdReq req) {
        return toAjax(facFacilityRepairsService.updateFacFacilityRepairs(req));
    }

    @ApiOperation("删除设备报修")
    //@PreAuthorize("@ss.hasPermi('facility:repairs:remove')")
    @Log(title = "设备报修", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(facFacilityRepairsService.deleteFacFacilityRepairsByIds(ids));
    }
}
